package com.yuanrui.practice.server.rpc;

import com.yuanrui.auth.api.UserFeignService;
import com.yuanrui.auth.entity.AuthUserDTO;
import com.yuanrui.auth.entity.Result;
import com.yuanrui.practice.server.entity.dto.UserInfo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 用户rpc
 */
@Component
public class UserRpc {
    @Resource
    private UserFeignService userFeignService;

    public UserInfo getUserInfo(String userName) {
        AuthUserDTO AuthUserDTO = new AuthUserDTO();
        AuthUserDTO.setUserName(userName);
        Result<AuthUserDTO> userInfo = userFeignService.getUserInfo(AuthUserDTO);
        if (userInfo.getSuccess()) {
            UserInfo userInfo1 = new UserInfo();
            userInfo1.setUserName(userInfo.getData().getUserName());
            userInfo1.setNickName(userInfo.getData().getNickName());
            userInfo1.setAvatar(userInfo.getData().getAvatar());
            return userInfo1;
        }else {
            return null;
        }
    }
}
